<!--_meta 作为公共模版分离出去-->
<!DOCTYPE HTML>
<html>
<head>
<#include "head.html">
<title>添加</title>
</head>
<body>
<article class="page-container">
	<form action="${contextPath}/sys/role/save.do" method="post" class="form form-horizontal" id="form">
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>角色名称：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<input type="text" class="input-text" required value="${entity.roleName}" placeholder="" id="roleName" name="roleName">
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-3">角色描述：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<input type="text" class="input-text" value="${entity.roleDesc}" placeholder="" id="" name="roleDesc">
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-3">角色权限：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<#if treeMenus??>
				<#list treeMenus as vo>
				<dl class="permission-list">
					<dt>
						<label>
							<#if menuIds??>
							<input type="checkbox" ${menuIds?seq_contains(vo.sysMenu.id)?string("checked", "")}
                                value="${(vo.sysMenu.id)!}" name="menuIds" id="user-Character-0">
							${(vo.sysMenu.menuName)!}</label>
							<#else>
							<input type="checkbox"
								value="${(vo.sysMenu.id)!}" name="menuIds" id="user-Character-0">
							${(vo.sysMenu.menuName)!}</label>
							</#if>
					</dt>
					<dd>
						<#if vo.children?? && (vo.children?size > 0)>
						<#list vo.children as ch>
						<dl class="cl permission-list2">
							<dt>
								<label class="">
									<#if menuIds??>
									<input type="checkbox" ${menuIds?seq_contains(ch.sysMenu.id)?string("checked", "")}
                                           value="${(ch.sysMenu.id)!}" name="menuIds" id="user-Character-0-0">
									${(ch.sysMenu.menuName)!}</label>
									<#else>
									<input type="checkbox"
											value="${(ch.sysMenu.id)!}" name="menuIds" id="user-Character-0-0">
									${(ch.sysMenu.menuName)!}</label>
									</#if>
							</dt>
							<dd>
								<#if ch.children?? && (ch.children?size > 0)>
								<#list ch.children as ci>
								<label class="">
									<#if menuIds??>
									<input type="checkbox" ${menuIds?seq_contains(ci.sysMenu.id)?string("checked", "")}
                                           value="${(ci.sysMenu.id)!}" name="menuIds" id="user-Character-0-0-0">
									${(ci.sysMenu.menuName)!}</label>
									<#else>
									<input type="checkbox"
											value="${(ci.sysMenu.id)!}" name="menuIds" id="user-Character-0-0-0">
									${(ci.sysMenu.menuName)!}</label>
									</#if>
								</#list>
								</#if>
							</dd>
						</dl>
						</#list>
						</#if>
					</dd>
				</dl>
				</#list>
				</#if>
			</div>
		</div>
		<div class="row cl">
			<div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
				<button type="submit" class="btn btn-success radius" id="admin-role-save" name="admin-role-save"><i class="icon-ok"></i> 确定</button>
			</div>
		</div>
		<input type="hidden" value="${entity.id}" name="id">
	</form>
</article>

<#include "footer.html">

<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript">
    $(function(){
        $(".permission-list dt input:checkbox").click(function(){
            $(this).closest("dl").find("dd input:checkbox").prop("checked",$(this).prop("checked"));
        });
        $(".permission-list2 dd input:checkbox").click(function(){
            var l =$(this).parent().parent().find("input:checked").length;
            var l2=$(this).parents(".permission-list").find(".permission-list2 dd").find("input:checked").length;
            if($(this).prop("checked")){
                $(this).closest("dl").find("dt input:checkbox").prop("checked",true);
                $(this).parents(".permission-list").find("dt").first().find("input:checkbox").prop("checked",true);
            }
            else{
                if(l==0){
                    $(this).closest("dl").find("dt input:checkbox").prop("checked",false);
                }
                if(l2==0){
                    $(this).parents(".permission-list").find("dt").first().find("input:checkbox").prop("checked",false);
                }
            }
        });

    });
</script>
<script type="text/javascript">
$(function(){
    $('.skin-minimal input').iCheck({
        checkboxClass: 'icheckbox-blue',
        radioClass: 'iradio-blue',
        increaseArea: '20%'
    })

	$("#form").validate({
		rules:{
		},
		onkeyup:false,
		focusCleanup:true,
		success:"valid",
		submitHandler:function(form){
			var options = {  
					url:$("#form").attr("action"),
	                success: function() {
	                	layer.alert('操作成功', function(index){
	  	                	var index = parent.layer.getFrameIndex(window.name);
	  	        			parent.$("[name='refresh']").click();
	  	        			parent.layer.close(index);
	                	});    
	                	
	                }   
	        }; 
			$(form).ajaxSubmit(options);
		}
	});
});
</script> 
<!--/请在上方写此页面业务相关的脚本-->
</body>
</html>